package com.example.LoadData;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import com.android.volley.toolbox.ImageLoader.ImageListener;
import com.android.volley.toolbox.NetworkImageView;
import com.example.Activity.MyApplication;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.widget.ImageView;
import com.example.Activity.R;

public class LoadImage {

	public static void loadImage(String url, ImageView imageView) {
		final LruCache<String, Bitmap> lruCache = new LruCache<String, Bitmap>(20);
		ImageCache imageCache = new ImageCache() {

			@Override
			public void putBitmap(String key, Bitmap bitmap) {
				lruCache.put(key, bitmap);
			}

			@Override
			public Bitmap getBitmap(String key) {
				return lruCache.get(key);
			}
		};
		ImageLoader imageLoader = new ImageLoader(MyApplication.getRequestQueue(), imageCache);
		ImageListener listener = ImageLoader.getImageListener(imageView, R.drawable.ic_launcher,
				R.drawable.ic_launcher);
		imageLoader.get(url, listener);
	}

	public static void loadNetWorkImageView(String url, NetworkImageView imageView) {
		final LruCache<String, Bitmap> lruCache = new LruCache<String, Bitmap>(20);
		ImageCache imageCache = new ImageCache() {

			@Override
			public void putBitmap(String key, Bitmap bitmap) {
				lruCache.put(key, bitmap);
			}

			@Override
			public Bitmap getBitmap(String key) {
				return lruCache.get(key);
			}
		};
		ImageLoader imageLoader = new ImageLoader(MyApplication.getRequestQueue(), imageCache);
		imageView.setTag("url");
		imageView.setImageUrl(url, imageLoader);
	}
}
